//
//  FileManager.m
//  McRemote
//
//  Created by Magic on 2/12/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "FileManager.h"

@implementation FileManager

+ (FileManager *)sharedManager
{
    static FileManager *sharedManager;
    static dispatch_once_t token;
    dispatch_once(&token, ^{
        sharedManager = [[FileManager alloc] init];
    });
    
    return sharedManager;
}

- (NSString *)documentDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                         NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    
    
    
    return path;
}

- (BOOL)fileExists:(NSString *)name extension:(NSString *)ext
{
    NSString *fileName = [name stringByAppendingFormat:@".%@",ext];
    NSString *filePath = [[self documentDirectory] stringByAppendingPathComponent:fileName];
    
    
    return [[NSFileManager defaultManager] fileExistsAtPath:filePath];
    
}

- (void)writeToDocument:(NSData *)data fileName:(NSString *)name extension:(NSString *)ext
{
    NSString *fileName = [name stringByAppendingFormat:@".%@",ext];
    NSString *filePath = [[self documentDirectory] stringByAppendingPathComponent:fileName];

    [data writeToFile:filePath atomically:YES];
}

- (UIImage *)imageNamed:(NSString *)name
{
    NSString *fileName = [name stringByAppendingString:@".png"];
    NSString *filePath = [[self documentDirectory] stringByAppendingPathComponent:fileName];
    //NSData *data = [NSData dataWithContentsOfFile:filePath];
    return [UIImage imageWithContentsOfFile:filePath];
}

@end
